<?php
	require_once('./lib/nusoap.php');
try {
	//$endpoint = "http://nrh.dyndns.org/demo/labReport.php";
	//$myNamespace = "http://nrh.dyndns.org/demo/labReport.php?wsdl";
	$endpoint = "http://nrh.dyndns.org/production/labReport.php";
	$myNamespace = "http://nrh.dyndns.org/production/labReport.php?wsdl";
	$wsdl = $myNamespace;
	//$client = new nusoap_client($wsdl,"wsdl")or die("eeee"); 
	$client = new nusoap_client($endpoint, false);

	$msg = $client->serializeEnvelope('<ns7030:InsertLabReport xmlns:ns7030="http://nrh.dyndns.org/" encoding="UTF-8">	
	<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:voc="urn:hl7-org:v3/voc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-InsType" xsi:schemaLocation="urn:hl7-org:v3 CDA.xsd"><typeId root="2.16.840.1.113883.1.3" extension="POCD_HD000040"/><id displayable="false"/><code displayName="Lab Report"/><effectiveTime value="2013103016000"/><confidentialityCode code="N" codeSystem="2.16.840.1.113883.5.25"/><setId root="DocumentID" extension="11470.11470-00001.2"/><versionNumber value="2"/><recordTarget><patientRole><id assigningAuthorityName="โรงพยาบาลนพรัตนราชธานี" extension="11470" root="HospCode"/><patient><id extension="1" root="HN"/><name><given>สมชาย</given><family>นามสกุลดี</family><Prefix>นาย</Prefix></name></patient></patientRole></recordTarget><author><time value="2013103016000"/><assignedAuthor><id assigningAuthorityName="PMK HIS"/><assignedAuthoringDevice><softwareName>PMK HIS</softwareName></assignedAuthoringDevice></assignedAuthor></author><custodian><assignedCustodian><representedCustodianOrganization><id assigningAuthorityName="พยาธิวิทยา"/><name>พยาธิวิทยา</name></representedCustodianOrganization></assignedCustodian></custodian><component><structuredBody><component><section><title>Lab Report</title><text>...</text><entry><labReport><patient><CitizenID>3000000000001</CitizenID><personName><Prefix>นาย</Prefix><GivenName>สมชาย</GivenName><MiddleName></MiddleName><FamilyName>นามสกุลดี</FamilyName></personName><Birthdate>1983-02-28</Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender>M</Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone>0810000001</Telephone><Email>som@gmail.com</Email><HospCode>11470</HospCode><Age></Age><HospitalNumber>1</HospitalNumber><AdmissionNumber></AdmissionNumber><BloodGroupABO>A</BloodGroupABO><BloodTypeRh>Positive</BloodTypeRh><PreDiagnosis></PreDiagnosis><insType></insType></patient><labResult><VisitingNumber>11470-00001</VisitingNumber><LabID>2</LabID><LabName>Chemistry</LabName><LabDate>2013-10-20 10:51:00</LabDate><WardID>1</WardID><WardName>อายุรกรรม</WardName><labRequester><CitizenID>12</CitizenID><personName><Prefix></Prefix><GivenName>วิวัฒน์</GivenName><MiddleName></MiddleName><FamilyName>บุญรักษา</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></labRequester><labResultDetail><LN></LN><labTestID>1</labTestID><UniversalTestName>SUGAR</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>98.0</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>1</UnitID><UnitName>mg/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>2</labTestID><UniversalTestName>BUN</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>15.5</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>1</UnitID><UnitName>mg/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>3</labTestID><UniversalTestName>CREATININE</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>1.0</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>1</UnitID><UnitName>mg/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>4</labTestID><UniversalTestName>URIC ACID</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>5.5</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>1</UnitID><UnitName>mg/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>5</labTestID><UniversalTestName>CHOLESTEROL</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>200</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>1</UnitID><UnitName>mg/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>6</labTestID><UniversalTestName>TOTAL PROTEIN</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>7.5</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>2</UnitID><UnitName>g/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>7</labTestID><UniversalTestName>ALBUMIN</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>5.3</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>2</UnitID><UnitName>g/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>8</labTestID><UniversalTestName>GLOBULIN</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>3.1</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>2</UnitID><UnitName>g/dl</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>9</labTestID><UniversalTestName>AST</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>25.0</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>3</UnitID><UnitName>U/L</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>10</labTestID><UniversalTestName>ALT</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>21.5</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>3</UnitID><UnitName>U/L</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail><labResultDetail><LN></LN><labTestID>11</labTestID><UniversalTestName>ALKALINE PHOSPHATASE</UniversalTestName><MethodID></MethodID><MethodName></MethodName><ResultTest>100.0</ResultTest><ReferenceResultTest></ReferenceResultTest><UnitID>3</UnitID><UnitName>U/L</UnitName><LabResultDate>2013-10-20 10:51:00</LabResultDate><ResultUniversal></ResultUniversal><referenceUniversal></referenceUniversal><UnitUniversal></UnitUniversal><LabReporter><CitizenID>11</CitizenID><personName><Prefix></Prefix><GivenName>สมหญิง</GivenName><MiddleName></MiddleName><FamilyName>สุดสวย</FamilyName></personName><Birthdate></Birthdate><BirthJurisdictionCountrySubDivision></BirthJurisdictionCountrySubDivision><Nationality></Nationality><Gender></Gender><Religion></Religion><LifeStatus></LifeStatus><Telephone></Telephone><Email></Email></LabReporter></labResultDetail></labResult></labReport></entry></section></component></structuredBody></component></ClinicalDocument>
</ns7030:InsertLabReport>');
		
$result = $client->send($msg, $endpoint);//or die("ttttttttttttttt");
if ($client->fault) {
		trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faulstring})", E_ERROR);
	} else {
		// Check for errors
		$err = $client->getError();
		if ($err) {
			// Display the error
			echo '<h2>Error</h2><pre>' . $err . '</pre>';
		} else {
			// Display the result
			echo '<h2>Result</h2><pre>';
			echo $result;
			print_r($result);
			echo '</pre>';
		}
	}
	
	
//echo $result;
//print_r($result);
//echo"xxxxxxxxxxxxxx";
} catch (Exception $e) {
		printf("MessAge = %s\n",$e->getMessAge());
}
?>
